﻿using Sunny.UI;
using System;

namespace Toolbox.form.box
{
    public partial class TimeStampForm : UIPage
    {
        public TimeStampForm()
        {
            InitializeComponent();
        }

        private void TimeStampForm_Load(object sender, EventArgs e)
        {
            // 窗体加载
            uiTextBox3.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            // 时间戳转北京时间
            DateTime beginTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long timeStamp = Convert.ToInt64(uiTextBox1.Text);
            DateTime dateTime = beginTime.AddMilliseconds(timeStamp);
            uiTextBox2.Text = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            // 北京时间转时间戳
            DateTime dateTime = Convert.ToDateTime(uiTextBox3.Text);
            DateTime beginTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long timeStamp = (long)(dateTime - beginTime).TotalMilliseconds;
            uiTextBox4.Text = timeStamp.ToString();
        }

        
    }
}
